<?php

namespace app\admin\model\commission;

use app\admin\model\Order;
use think\Model;
use traits\model\SoftDelete;

class Rate extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'commission_rate';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';
    // 追加属性

    /*获取指定金额的佣金*/
    public function getCommission($level)
    {
        $rate = $this->field(["id","level"])
            ->where("status",1)
            ->order('level', 'asc')
            ->select();
        $id=1;
        foreach ($rate as $k => $v) {
            if($level>=$v['level']){
                $id=$v["id"];
            }else{
                break;
            }
        }
        return $this->field(["id","level","platform","agent","room","parent","parent2","text"])
            ->where("id",$id)->find();
    }

    public function getStatusList()
    {
        return ['1' => __('开启'),'0' => __('关闭'),];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
